package com.itzmn.newcode.offer1;

/**
 * @Author: 张梦楠
 * @Date: 2018/12/18 16:33
 * 简书：https://www.jianshu.com/u/d611be10d1a6
 * 码云：https://gitee.com/zhangqiye
 * @Description: 数值的整数次方
 *
 *  给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
 *
 */
public class _12_NumericalIntegerPower {

    public static void main(String[] args) {
        new _12_NumericalIntegerPower().test();
    }

    private void test() {
        Power(2.4,5);
    }

    public double Power(double base, int exponent) {

        double sum = 1;
        if (exponent>0){
            for (int i=0;i<exponent;i++){
                sum*=base;
            }
        }
        if (exponent<0){
            int c = -exponent;
            for (int i=0;i<c;i++){
                sum/=base;
            }
        }

        return sum;
    }
}
